package operation;

import book.Book;
import book.BookLise;

import java.util.Scanner;

public class AddOperation implements  IOperation {
    @Override
    public void work(BookLise bookLise) {
        System.out.println("增加图书");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你增加查找的图书名字");
        String name = scanner.nextLine();
        System.out.println("请输入你增加查找的图书作者");
        String author = scanner.nextLine();
        System.out.println("请输入你增加查找的图书类型");
        String type = scanner.nextLine();
        System.out.println("请输入你增加查找的图书价格");
        int price = scanner.nextInt();

        for (int i = 0; i < bookLise.getNowSize(); i++) {
            if (name.equals(bookLise.getBooks(i).getName())) {
                System.out.println("不能添加重复的书籍");
                return;
            }
        }

        bookLise.setBooks(new Book(name,author,type,price),bookLise.getNowSize());
        bookLise.setNowSize(bookLise.getNowSize()+1);
        System.out.println("《"+ name + "》" + "增加成功");
    }
}
